Skip to content

Conversation

@davisadam10
Copy link
Collaborator

The Daylight and Blackbody options have been used by folks in production who reported it not working.
Needed to add handling to pass the custom temperature through to the backend
Needed to add in the code to calculate and get the illuminent for those two options

… daylight with custom temperatures

These need to be passed through and handled in the backend to ensure we get the right illuminant
We also have to update the cache_Key to invalidate the cache if the lluminant changes other wise we run with the wrong settings
@davisadam10 davisadam10 requested a review from KelSolaar October 14, 2025 09:39
raise ValueError(msg)
# Apply the correction factor as per CIE 015:2004 recommendation
CCT_corrected = temperature * 1.4388 / 1.4380
xy = CCT_to_xy_CIE_D(CCT_corrected)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KelSolaar thomas sir would be great if you can double check for me this is the right way to handle black body and daylight options.

@KelSolaar
Copy link
Collaborator

There is something quite not right about this as the UI does already some of that work (the function is actually duplicated already), we should probably consolidate this so that there is only one entry point to generate the illuminants.

def set_illuminant_datable(illuminant, CCT):
    """
    Set the *Illuminant* `DataTable` content for given illuminant name.

    Parameters
    ----------
    illuminant : str
        Existing illuminant name or *Custom*, *Daylight* or *Blackbody*.
    CCT : numeric
        Custom correlated colour temperature (CCT) used for the *Daylight* and
        *Blackbody* illuminant types.

    Returns
    -------
    tuple
        Tuple of data and columns.
    """

    logging.info(
        'Setting illuminant datatable for "%s" illuminant and "%s" CCT...',
        illuminant,
        CCT,
    )

    labels = ["Wavelength", "Irradiance"]
    ids = ["wavelength", "irradiance"]
    precision = [
        None,
        Format(precision=DATATABLE_DECIMALS, scheme=Scheme.fixed),
    ]
    columns = [
        {
            "id": ids[i],
            "name": label,
            "type": "numeric",
            "format": precision[i],
        }
        for i, label in enumerate(labels)
    ]

    if illuminant == "Custom":
        data = [
            dict(wavelength=wavelength, irradiance=None)
            for wavelength in CUSTOM_WAVELENGTHS
        ]

    else:
        if illuminant == "Daylight":
            xy = CCT_to_xy_CIE_D(CCT * 1.4388 / 1.4380)
            illuminant = sd_CIE_illuminant_D_series(xy)
        elif illuminant == "Blackbody":
            illuminant = sd_blackbody(CCT)
        else:
            illuminant = SDS_ILLUMINANTS[illuminant]

        data = [
            dict(
                wavelength=wavelength,
                irradiance=illuminant[wavelength],
            )
            for wavelength in illuminant.wavelengths
        ]

    return data, columns

Thoughts?

@davisadam10
Copy link
Collaborator Author

Hey @KelSolaar 100%

And exactly the kind of info i was looking from you!

In general there seems to be a fair amount of logic remianing in the UI which we should move either to the common helper functions, or the application itself that the UI then only has to deal with updating the display vs processing any data.

@davisadam10
Copy link
Collaborator Author

Ill try and make a stab at this change later in the week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants